package ipdesk.model.analysis.action;

import ipdesk.model.analysis.bean.AnalysisPromoteBean;
import ipdesk.model.analysis.dao.AnalysisPromoteDao;
import ipdesk.model.analysis.dao.AnalysisSeminarDao;

import java.util.List;

import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;
import com.opensymphony.xwork2.Preparable;

import ecg.util.Time;

public class AnalysisPromoteAction extends ActionSupport implements Preparable, ModelDriven<AnalysisPromoteBean>
{
	private AnalysisPromoteBean analysisPromoteBean;
	private List<AnalysisPromoteBean> yearList;
	private List<AnalysisPromoteBean> analysisPromoteList;
	private List<AnalysisPromoteBean> analysisPromoteListByMonth;
	
	
	
	

	public String execute() throws Exception
	{
		
		// 1. 년도 셀렉트 박스 리스트를 가져온다.
		yearList = AnalysisPromoteDao.getInstance().getYears();
		
		
		// 2. 조회에 필요한 년도 파라메터가 없다면 올해로 검색한다.
		String selectedYear = "";
		
		if(analysisPromoteBean.getSelectedYear() == null || "".equals(analysisPromoteBean.getSelectedYear())){
			selectedYear = Time.getYear();
			analysisPromoteBean.setSelectedYear(selectedYear);
		}else{
			selectedYear = analysisPromoteBean.getSelectedYear();
		}
		
		analysisPromoteList = AnalysisPromoteDao.getInstance().getAnalysisPromoteList(selectedYear);
		//System.out.println("analysisPromoteList.size() ::: "+analysisPromoteList.size());
		
		return SUCCESS;
	}

	public String executeGetDaysResults() throws Exception
	{
		// 1. 페이지에서 가져온, 년도, 월에 따른 마지막 일자를 구한다.
		String selectedYear = "";
		String month		= "";
		int days			= 0;
		
		if(analysisPromoteBean.getSelectedYear() == null || "".equals(analysisPromoteBean.getSelectedYear())){
			selectedYear = Time.getYear();
			analysisPromoteBean.setSelectedYear(selectedYear);
		}else{
			selectedYear = analysisPromoteBean.getSelectedYear();
		}
		//System.out.println("selectedYear : "+selectedYear);
		if(analysisPromoteBean.getMonth() == null || "".equals(analysisPromoteBean.getMonth())){
			month = "01";
			analysisPromoteBean.setMonth(month);
		}else{
			month = analysisPromoteBean.getMonth();
		}
		//System.out.println("month : "+month);
		
		days = Time.getLastDay(selectedYear, month);
		analysisPromoteBean.setDays(String.valueOf(days));
		//System.out.println("days : "+days);
		
		// 2. 쿼리 요청
		
		analysisPromoteListByMonth = AnalysisPromoteDao.getInstance().getAnalysisPromoteListByMonth(analysisPromoteBean);
		//System.out.println("analysisSeminarListByMonth.size :: "+analysisSeminarListByMonth.size());
		return SUCCESS;
	}
	
	public void prepare() throws Exception {
		analysisPromoteBean = new AnalysisPromoteBean();
		
	}

	public AnalysisPromoteBean getModel() {

		return analysisPromoteBean;
	}

	public List<AnalysisPromoteBean> getYearList() {
		return yearList;
	}

	public List<AnalysisPromoteBean> getAnalysisPromoteList() {
		return analysisPromoteList;
	}
	
	public List<AnalysisPromoteBean> getAnalysisPromoteListByMonth() {
		return analysisPromoteListByMonth;
	}
}

